home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 43.zip / Sources C- WorkDisk V.adf / ex / checkdisk3.c < prev    next >
C/C++ Source or Header  |  1987-02-16  |  3KB  |  99 lines

  1. /* checkdisk.c */
  2.  
  3. #include "exec/types.h"
  4. #include "devices/trackdisk.h"
  5.  
  6. #define TD_READ CMD_READ
  7. #define BLOCKSIZE TD_SECTOR
  8.  
  9. struct MsgPort *diskport;
  10. struct IOExtTD *diskreq;
  11. BYTE diskbuffer[BLOCKSIZE];
  12.  
  13. extern struct MsgPort *CreatePort();
  14. extern struct IORequest *CreateExtIO();
  15.  
  16. void MotorOnOff(onoff)
  17. long onoff;
  18. {
  19.     /* TURN ON/OFF DISK MOTOR ... old motor state is returned in io_Actual */
  20.     diskreq->iotd_Req.io_Length = onoff;
  21.     /* this says motor is to be turned on */
  22.     diskreq->iotd_Req.io_Command = TD_MOTOR;
  23.     /* do something with the motor */
  24.     DoIO(diskreq);
  25. }
  26.  
  27.  
  28. main(argc,argv)
  29. int argc;
  30. char *argv[];
  31. {
  32. SHORT cylinder,head,sector;
  33. register short headcylinderterm, cylinderterm;
  34. LONG unit,error;
  35.  
  36. if (argc>1)
  37. {
  38.  unit = atoi(argv[1]);
  39.  if( unit < 0 || unit > 3) exit(4);
  40. }
  41. else
  42.  unit = 1;
  43.     
  44. diskport = CreatePort(0,0);
  45. if(diskport == 0) exit(1);    /* error in createport */
  46. diskreq = (struct IOExtTD *)CreateExtIO(diskport, sizeof(struct IOExtTD));     
  47.         /* make an io request block for communicating with the disk */
  48. if(diskreq == 0) { DeletePort(diskport); exit(2); }    
  49.  
  50. error = OpenDevice(TD_NAME,unit,diskreq,0);
  51. if(error)
  52.  {
  53.   DeleteExtIO(diskreq, sizeof(struct IOExtTD));
  54.   DeletePort(diskport);
  55.   exit(3);
  56.  }
  57. MotorOnOff(1);
  58.  
  59. for(cylinder=0; cylinder<80; cylinder++)    /* tracks to test */
  60. {
  61.  cylinderterm = NUMSECS * NUMHEADS * cylinder;
  62.  for(head=0; head<2; head++)    /* number of heads to test */
  63.  {
  64.   headcylinderterm = NUMSECS * head + cylinderterm; 
  65.   for(sector=0; sector<11; sector++)    /* sectors to test */
  66.   {
  67.    diskreq->iotd_Req.io_Flags = 0;      
  68.    diskreq->iotd_Req.io_Length = BLOCKSIZE;      
  69.    diskreq->iotd_Req.io_Data = (APTR)diskbuffer;    
  70.    diskreq->iotd_Req.io_Offset = (long) (TD_SECTOR * (sector + headcylinderterm));
  71.    diskreq->iotd_Req.io_Command = ETD_READ;
  72.         /* check that disk not changed before reading */
  73.    diskreq->iotd_Count = 0xFFFFFFFF;
  74.    diskreq->iotd_SecLabel = 0;        
  75.     
  76.     /* convert from cylinder, head, sector to byte-offset value to get
  77.         * right one (as dos and everyone else sees it)...*/
  78.     
  79.     /* driver reads one CYLINDER at a time (head does not move for
  80.      * 22 sequential sector reads, or better-put, head doesnt move for
  81.      * 2 sequential full track reads.)
  82.      */
  83.  
  84.    DoIO(diskreq);
  85.  
  86.    if(diskreq->iotd_Req.io_Error != 0) 
  87.    printf("\nError nr. Error=%ld at Cyl=%ld, Sc=%ld, Hd=%ld",
  88.         diskreq->iotd_Req.io_Error,cylinder,sector,head);
  89.   }
  90.  }
  91. }
  92. MotorOnOff(0);
  93. CloseDevice(diskreq);
  94.  
  95. DeleteExtIO(diskreq, sizeof(struct IOExtTD));
  96. DeletePort(diskport);
  97. }    /* end of main */
  98.  
  99.